Skip to content

gateway: add HMAC request signature authentication - #4652

Open
gousteris wants to merge 1 commit into
mainfrom
gateway-hmac-auth
Open

gateway: add HMAC request signature authentication#4652
gousteris wants to merge 1 commit into
mainfrom
gateway-hmac-auth

Conversation

@gousteris

@gousteris gousteris commented Jul 31, 2026

Copy link
Copy Markdown
Contributor

Adds an optional auth.hmac config block to the gateway input that authenticates incoming requests by verifying a hex-encoded HMAC signature (SHA-256 or SHA-512) of the raw request body against a shared secret, read from a configurable request header. When set it replaces the platform-managed JWT/RBAC authentication for the endpoint, supporting webhook-style callers that sign their payloads instead of presenting a bearer token (e.g. Terraform Cloud Run Tasks).

The auth block is designed as an extension point for additional authentication mechanisms in the future.

jira: DEVPROD-4607

@CLAassistant

CLAassistant commented Jul 31, 2026

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

Comment thread internal/gateway/hmac.go
@gousteris
gousteris force-pushed the gateway-hmac-auth branch from c60b2da to 8b9e740 Compare July 31, 2026 13:51
Comment thread internal/impl/gateway/input.go Outdated
@gousteris
gousteris force-pushed the gateway-hmac-auth branch 3 times, most recently from 244b87a to b4539f1 Compare August 4, 2026 14:14
Comment thread internal/gateway/hmac.go Outdated
Comment on lines +115 to +131
signatureHex := req.Header.Get(m.header)
if signatureHex == "" {
m.logger.With("header", m.header).Error("Signature header not found")
http.Error(w, "signature header not found", http.StatusUnauthorized)
return
}

signatureHex, ok := strings.CutPrefix(signatureHex, m.prefix)
if !ok {
m.logger.Debug("Signature prefix mismatch")
http.Error(w, "signature verification failed", http.StatusUnauthorized)
return
}

signature, err := hex.DecodeString(signatureHex)
if err != nil {
m.logger.With("error", err).Error("Signature header is not valid hex")

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rejection paths log at Error level for ordinary client-side auth failures (CONTRIBUTING.md §1.2.2)

1.2.2 Provides relevant logging to support troubleshooting. Unexpected behavior should emit warning or error logs. Normal operation should emit no logs.

A missing signature header (L117), a non-hex header value (L131) and a MAC mismatch (L166) are all fully attacker-controlled inputs on what is by design an internet-facing webhook endpoint. Any unauthenticated caller — including background port/path scanners, which will hit this path constantly — can therefore drive unbounded Error-level log volume, which pollutes logs and can fire error-rate alerts for what is normal operation of an authenticating endpoint.

This is also internally inconsistent: the prefix mismatch (L124) and signature length mismatch (L140) paths — the same class of "the caller sent a bad signature" event — log at Debug.

Suggested fix: demote the four caller-error rejection paths (missing header, bad hex, length mismatch, MAC mismatch) to Debug so they stay diagnosable without being remotely triggerable noise, keeping Warn/Error for conditions that indicate a real problem on our side (e.g. the body read failure at L154). If visibility into auth failures is wanted, a counter metric (§1.2.1) is a better fit than a per-request error log.

Adds an optional auth.hmac config block to the gateway input that
authenticates incoming requests by verifying a hex-encoded HMAC
signature (SHA-256 or SHA-512) of the raw request body against a
shared secret, read from a configurable request header. When set it
replaces the platform-managed JWT/RBAC authentication for the
endpoint, supporting webhook-style callers that sign their payloads
instead of presenting a bearer token (e.g. Terraform Cloud Run Tasks).

The auth block is designed as an extension point for additional
authentication mechanisms in the future.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants